﻿@using RuoVea.ExEnum
@using RuoVea.OmiApi.Article.Service
@using RuoVea.OmiApi.Dict.Entitys
@using RuoVea.OmiApi.Dict.Service
@using RuoVea.OmiApi.Article.Service.Dto
@inject ArticleService _articleService;
@inject SysDictValueService sysDictValueService;
@{
    Layout = "_Layout";
    int currentPageNo = Context.Request.Query.ContainsKey("pageNo") ? int.TryParse(Context.Request.Query["pageNo"], out var page) ? page : 1 : 1;
    var articleList = await _articleService.GetPagesAsync(new ArticleParam { CategorieIsDisable = YesOrNot.N, PageNo = currentPageNo, PageSize = 10 });
    int totalPage = articleList.TotalRows == 0 ? 1 : (int)Math.Ceiling((double)articleList.TotalRows / articleList.PageSize);
    int currentPage = Math.Max(1, Math.Min(currentPageNo, totalPage));

    List<SysDictValue> homebanner = await sysDictValueService.GetDictDataListByCodeCache("HOMEBANNER");
    List<SysDictValue> recommended = await sysDictValueService.GetDictDataListByCodeCache("RECOMMENDED");
    
    int k = homebanner.Count();
}

<div class="recommend-index">
    <div class="recommend-top">

        <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
            <ol class="carousel-indicators">
               @for(var j=0;j<k;j++){
                    <li data-target="#carouselExampleIndicators" data-slide-to="@j" "@(j == 0 ? "class='active'" : "")"></li>
                }
            </ol>
            <div class="carousel-inner">
                @for (var c = 0; c < k; c++)
                {
                    <div class="carousel-item @(c==0?"active":"")"> <img class="d-block w-100" src="@homebanner[c].ExtData" alt="@homebanner[c].Label"> </div>
                }
            </div>
            <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
                <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                <span class="sr-only">Previous</span>
            </a>
            <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
                <span class="carousel-control-next-icon" aria-hidden="true"></span>
                <span class="sr-only">Next</span>
            </a>
        </div>
    </div>
    <div class="recommend-bottom">
        @foreach (var t in recommended)
        {
            <div class="recommend-item">
                <a><img src="@t.ExtData" class="img-fluid" alt=""></a>
            </div>
        }
@*<div class="recommend-item"><a href="calmlog-details.html"><img src="~/lib/temporary-img/recommended-right.jpg" class="img-fluid" alt=""></a></div>*@
    </div>

</div>
@foreach (var c in articleList.Rows)
{
    <div class="cl-card">
        <div class="row">
            <div class="col-lg-3 col-md-4 col-sm-12 cl-card-image"><a href="@($"Details/{c.Id}.html")"><img src="@c.CoverImage" class="img-fluid" alt=""></a></div>
            <div class="col-lg-9 col-md-8 col-sm-12 cl-card-main">
                <h3 class="cl-card-main-title"><a href="@($"Details/{c.Id}.html")">@Html.Raw(c.Title)</a></h3>
                <p class="cl-card-main-info">@Html.Raw(c.Summary)</p>
                <p class="cl-card-more"><a href="@($"Details/{c.Id}.html")">阅读更多...</a></p>
            </div>
        </div>
    </div>
}

<nav aria-label="Page navigation">
    <ul class="pagination justify-content-center">
        <li class="page-item @(currentPage == 1 ? "disabled" : "")">
            <a class="page-link" href="?pageNo=@(currentPage - 1)">&laquo;</a>
        </li>
        @for (int i = 1; i <= totalPage; i++)
        {
            <li class="page-item @(i == currentPage ? "active" : "")">
                <a class="page-link" href="?pageNo=@i">@i</a>
            </li>
        }
        <li class="page-item @(currentPage == totalPage ? "disabled" : "")">
            <a class="page-link" href="?pageNo=@(currentPage + 1)">&raquo;</a>
        </li>
    </ul>
</nav>

<div class="text-center text-muted small mt-2">
    @{
        int startItem = (currentPage - 1) * articleList.PageSize + 1;
        int endItem = Math.Min(currentPage * articleList.PageSize, articleList.TotalRows);
    }
    显示 @startItem 到 @endItem 条，共 @articleList.TotalRows 条记录
</div>